/**
*排行榜Item 
**/

cc.Class({
    extends: cc.Component,

    properties: {
        itemBg:cc.Node,
        spTop:cc.Sprite,
        lbTop:cc.Label,
        spHeadImg:cc.Sprite,
        txtTopNum:cc.Label,
        txtName:cc.Label,
        spTopIcon:{
            default:[],
            type:[cc.SpriteFrame]
        },
    },


    // onLoad () {},

    setData:function(data,index){
        this.data = data;
        // console.log("topItem-setData:"+JSON.stringify(data));
        this.txtTopNum.string = data.h_score;
        this.txtName.string = data.nickname;
        let image =wx.createImage();
        var that = this;
        image.onload = function(){
            let texture = new cc.Texture2D();
            texture.initWithElement(image);
            texture.handleLoadedTexture();
            that.spHeadImg.spriteFrame = new cc.SpriteFrame(texture);
        }
        image.src = data.avatarUrl;

        this.itemBg.active = true;
        this.lbTop.node.active = (index>=3);
         this.spTop.node.active = (index < 3);
        if(index<3){
            this.spTop.spriteFrame = this.spTopIcon[index];
        }else{
            this.lbTop.string = index+1;
        }
    },
});
